home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / MacFormat 92 CD / Shareware Plus / Utilities / FolderSynchronizer 1.8.9 / FoldersSynchronizer / FoldersSynchronizer.9 / AllScripts_4_Funzioni.ls < prev    next >
Encoding:
Text File  |  2000-05-10  |  28.0 KB  |  936 lines

  1. on Funzioni_________________________
  2. end
  3.  
  4. on InitSeparator
  5.   global gSep
  6.   if PC() then
  7.     set gSep to "\"
  8.   else
  9.     set gSep to ":"
  10.   end if
  11. end
  12.  
  13. on PC
  14.   if the machineType = 256 then
  15.     return 1
  16.   else
  17.     return 0
  18.   end if
  19. end
  20.  
  21. on MAC
  22.   if the machineType = 256 then
  23.     return 0
  24.   else
  25.     return 1
  26.   end if
  27. end
  28.  
  29. on Sinistra stringa, Valore
  30.   set lun to length(stringa)
  31.   if Valore > lun then
  32.     set Valore to lun
  33.   end if
  34.   if (Valore > 0) and (Valore <= lun) then
  35.     return char 1 to Valore of stringa
  36.   end if
  37. end
  38.  
  39. on Centro stringa, inizio, fine
  40.   set lun to length(stringa)
  41.   if voidp(fine) then
  42.     set fine to lun
  43.   end if
  44.   if (inizio > 0) and (fine <= lun) then
  45.     return char inizio to fine of stringa
  46.   end if
  47. end
  48.  
  49. on Destra stringa, Valore
  50.   set lun to length(stringa)
  51.   if Valore > lun then
  52.     set Valore to lun
  53.   end if
  54.   if (Valore >= 0) and (Valore <= lun) then
  55.     set pos to lun - Valore + 1
  56.     return char pos to lun of stringa
  57.   end if
  58. end
  59.  
  60. on BtnUp Bottone
  61.   if Bottone <> EMPTY then
  62.     set BottoneUp to "BtnUp" & char 6 to the length of Bottone of Bottone
  63.     return BottoneUp
  64.   end if
  65. end
  66.  
  67. on BtnDw BottoneUp
  68.   set BottoneDw to "BtnDw" & char 6 to the length of BottoneUp of BottoneUp
  69.   return BottoneDw
  70. end
  71.  
  72. on BtnRL BottoneUp
  73.   set BottoneRL to "BtnRL" & char 6 to the length of BottoneUp of BottoneUp
  74.   return BottoneRL
  75. end
  76.  
  77. on BtnOf BottoneUp
  78.   set BottoneOf to "BtnOf" & char 6 to the length of BottoneUp of BottoneUp
  79.   return BottoneOf
  80. end
  81.  
  82. on BtnName BottoneUp
  83.   set Bottone to char 6 to the length of BottoneUp of BottoneUp
  84.   return Bottone
  85. end
  86.  
  87. on BtnICNName BottoneUp
  88.   set Bottone to char 9 to the length of BottoneUp of BottoneUp
  89.   return Bottone
  90. end
  91.  
  92. on stageTop
  93.   if the frontWindow = the stage then
  94.     return 1
  95.   end if
  96.   return 0
  97. end
  98.  
  99. on BtnChK mySprite, myRoll, myVariable
  100.   global gRememberFolders, gBeepWhenDone, gSaveLogFile, gDestructive, gInvisible, gUnlockFile, gAskConfirm, gTempMultiAll, gRememberMultiList, gTempTimerAll, gTempTimerWhenNeeded, gTempRememberTimer, gTempDoAndQuit
  101.   set myBtnUp to the name of member the member of sprite mySprite
  102.   set myValue to value(the last char in myBtnUp)
  103.   repeat while the stillDown
  104.     if the rollOver = myRoll then
  105.       set the member of sprite mySprite to BtnDw(myBtnUp)
  106.     else
  107.       set the member of sprite mySprite to myBtnUp
  108.     end if
  109.     updateStage()
  110.   end repeat
  111.   set the member of sprite mySprite to myBtnUp
  112.   updateStage()
  113.   if the rollOver = myRoll then
  114.     set myscript to "set " & myVariable && "= not" && myVariable
  115.     do(myscript)
  116.     put value(myVariable) into char length(myBtnUp) of myBtnUp
  117.   end if
  118.   set the member of sprite mySprite to myBtnUp
  119.   updateStage()
  120. end
  121.  
  122. on BtnCHKDirection mySprite, myRoll
  123.   global gOneDirection
  124.   set myBtnUp to the name of member the member of sprite mySprite
  125.   set myValue to value(the last char in myBtnUp)
  126.   repeat while the stillDown
  127.     if the rollOver = myRoll then
  128.       set the member of sprite mySprite to BtnDw(myBtnUp)
  129.     else
  130.       set the member of sprite mySprite to myBtnUp
  131.     end if
  132.     updateStage()
  133.   end repeat
  134.   set the member of sprite mySprite to myBtnUp
  135.   updateStage()
  136.   if the rollOver = myRoll then
  137.     set gOneDirection to not gOneDirection
  138.     put char 1 of string(gOneDirection) into char length(myBtnUp) of myBtnUp
  139.     set myPoint to point(the left of sprite 17 - 3, the top of sprite 17 - 3)
  140.     if not gOneDirection then
  141.       set the loc of sprite 50 to myPoint
  142.     else
  143.       set the locV of sprite 50 to -1000
  144.     end if
  145.     CheckOneDirection()
  146.   end if
  147.   set the member of sprite mySprite to myBtnUp
  148.   updateStage()
  149. end
  150.  
  151. on SetRadiogOnErrorDo
  152.   global gOnErrorDo
  153.   if voidp(gOnErrorDo) then
  154.     set gOnErrorDo to 0
  155.   end if
  156.   if (gOnErrorDo <> 0) and (gOnErrorDo <> 1) and (gOnErrorDo <> 2) then
  157.     set gOnErrorDo to 0
  158.   end if
  159.   set the member of sprite 28 to "BtnUpRadio0"
  160.   set the member of sprite 30 to "BtnUpRadio0"
  161.   set the member of sprite 32 to "BtnUpRadio0"
  162.   case gOnErrorDo of
  163.     0:
  164.       set mySprite to 28
  165.     1:
  166.       set mySprite to 30
  167.     2:
  168.       set mySprite to 32
  169.   end case
  170.   set the member of sprite mySprite to "BtnUpRadio1"
  171. end
  172.  
  173. on OpenMyFile nomefile
  174.   set file to new(xtra("fileio"))
  175.   if objectp(file) then
  176.     set err to openFile(file, nomefile, 1)
  177.     if err = 0 then
  178.       set myContent to readFile(file)
  179.       closeFile(file)
  180.       set file to 0
  181.       return myContent
  182.     else
  183.       return 0
  184.     end if
  185.   end if
  186.   return 0
  187. end
  188.  
  189. on DisplaySaveMyFile nomefile
  190.   set file to new(xtra("fileio"))
  191.   if objectp(file) then
  192.     set nomefile to displaySave(file, "Save the file as:", nomefile)
  193.     set file to 0
  194.     return nomefile
  195.   end if
  196.   set file to 0
  197.   return EMPTY
  198. end
  199.  
  200. on DisplayOpenMyFile type
  201.   set file to new(xtra("fileio"))
  202.   if objectp(file) then
  203.     if length(type) = 4 then
  204.       setFilterMask(file, type)
  205.     end if
  206.     set nomefile to displayOpen(file)
  207.     set file to 0
  208.     return nomefile
  209.   end if
  210.   set file to 0
  211.   return EMPTY
  212. end
  213.  
  214. on SaveTextFile nomefile, stringa, tipo, creat
  215.   if voidp(tipo) then
  216.     set tipo to "pref"
  217.   end if
  218.   if voidp(creat) then
  219.     set creat to "ttxt"
  220.   end if
  221.   set file to new(xtra("fileio"))
  222.   if objectp(file) then
  223.     createFile(file, nomefile)
  224.     openFile(file, nomefile, 0)
  225.     writeString(file, stringa)
  226.     setFinderInfo(file, tipo && creat)
  227.     closeFile(file)
  228.     set file to 0
  229.   end if
  230. end
  231.  
  232. on GetType myFile
  233.   set myType to Sinistra(OSGetFileInfo(myFile), 4)
  234.   return myType
  235. end
  236.  
  237. on GetCreator myFile
  238.   set myCreator to Destra(OSGetFileInfo(myFile), 4)
  239.   return myCreator
  240. end
  241.  
  242. on RimuoviLineFeed Testo
  243.   set n to the number of lines in Testo
  244.   set mytesto to EMPTY
  245.   repeat with i = 1 to n - 1
  246.     put line i of Testo & RETURN after mytesto
  247.   end repeat
  248.   put line n of Testo after mytesto
  249.   return mytesto
  250. end
  251.  
  252. on InitMonitor
  253.   global gMyMonitor, gMyMonitorLeft, gMyMonitorTop, gMyWidthMonitor, gMyHeightMonitor, gCentroMonitorH, gCentroMonitorV, gMyStageWidth, gMyStageHeight
  254.   set oldDelimiter to the itemDelimiter
  255.   set the itemDelimiter to ","
  256.   set x to getAt(the deskTopRectList, 1)
  257.   set a to item 1 of string(x)
  258.   set gMyMonitorLeft to value(char 6 to length(a) of a)
  259.   set gMyMonitorTop to value(item 2 of string(x))
  260.   set gMyWidthMonitor to value(item 3 of string(x)) - gMyMonitorLeft
  261.   set gMyHeightMonitor to value(item 4 of string(x)) - gMyMonitorTop
  262.   set gCentroMonitorH to gMyWidthMonitor / 2
  263.   set gCentroMonitorV to gMyHeightMonitor / 2
  264.   set gMyStageWidth to the stageRight - the stageLeft
  265.   set gMyStageHeight to the stageBottom - the stageTop
  266.   if (gMyWidthMonitor >= 832) and (gMyHeightMonitor >= 624) then
  267.     set gMyMonitor to 17
  268.   else
  269.     if (gMyWidthMonitor >= 360) and (gMyHeightMonitor >= 360) then
  270.       set gMyMonitor to 13
  271.     else
  272.       alert("It requires at least 360x360 monitor resolution.")
  273.       quit()
  274.     end if
  275.   end if
  276.   set the itemDelimiter to oldDelimiter
  277. end
  278.  
  279. on InitColor
  280.   global colorMark, ColorUnMark
  281.   if PC() then
  282.     set topdepth to 24
  283.   else
  284.     set topdepth to 32
  285.   end if
  286.   set the colorDepth to 16
  287.   if the colorDepth <> 16 then
  288.     set the colorDepth to topdepth
  289.     if the colorDepth <> topdepth then
  290.       set the colorDepth to 8
  291.       if the colorDepth <> 8 then
  292.         alert("Sono necessari almeno 256 colori.")
  293.         quit()
  294.       else
  295.         alert("Questo monitor pu√≤ visualizzare soltanto 256 colori dei 65.536 presenti. La qualit√† delle immagini potrebbe non essere buona.")
  296.         set colorMark to 29
  297.         set ColorUnMark to 255
  298.       end if
  299.     else
  300.       if the machineType = 256 then
  301.         set colorMark to 31
  302.         set ColorUnMark to 255
  303.       else
  304.         set colorMark to 16724736
  305.         set ColorUnMark to 0
  306.       end if
  307.     end if
  308.   else
  309.     if the machineType = 256 then
  310.       set colorMark to 31
  311.       set ColorUnMark to 255
  312.     else
  313.       set colorMark to 31936
  314.       set ColorUnMark to 0
  315.     end if
  316.   end if
  317. end
  318.  
  319. on InitXTRAs
  320.   global gSep, gDirXTRAs, gLastBackUpDate
  321.   if MAC() then
  322.     set gSep to ":"
  323.     set gDirXTRAs to the pathName & "PlugIn:"
  324.     openXLib(gDirXTRAs & "OS")
  325.     OSRegister(2014785220, 551689600)
  326.     openXLib(gDirXTRAs & "K2")
  327.     dosRegister(9888639)
  328.     openXLib(gDirXTRAs & "Files")
  329.     openXLib(gDirXTRAs & "WebF")
  330.     openXLib(gDirXTRAs & "WebL")
  331.   else
  332.     set gDirXTRAs to the pathName & "XTRAsPC\"
  333.     openXLib(gDirXTRAs & "OSUtil.x32")
  334.     OSRegister(1978087018, 50958600)
  335.   end if
  336.   set gLastBackUpDate to [TodayYear(1), TodayMonth(1), TodayDay(1)]
  337. end
  338.  
  339. on InitFolders
  340.   global gSep, gThisVersion, gDirPref, gDirDialog, gNomeFilePref, gDirLog, gDirXTRAs
  341.   if MAC() then
  342.     set gDirPref to OSSpecialPath("pref") & ":"
  343.   else
  344.     set gDirPref to "C:\"
  345.   end if
  346.   set gNomeFilePref to "FoldersSync" && gThisVersion && "Prefs"
  347.   set gDirDialog to gDirXTRAs
  348.   set gDirLog to the pathName & "Log Files" & gSep
  349. end
  350.  
  351. on ExtractFileNameFromPath myPath
  352.   global gSep
  353.   set oldDelimiter to the itemDelimiter
  354.   set the itemDelimiter to gSep
  355.   if the last char in myPath = gSep then
  356.     delete char -30000 of myPath
  357.   end if
  358.   set myReturn to the last item in myPath
  359.   set the itemDelimiter to oldDelimiter
  360.   return myReturn
  361. end
  362.  
  363. on ExtractParentFolder myPath
  364.   global gSep
  365.   set oldDelimiter to the itemDelimiter
  366.   set the itemDelimiter to gSep
  367.   if the last char in myPath = gSep then
  368.     delete char -30000 of myPath
  369.   end if
  370.   set k to the number of items in myPath - 1
  371.   set myReturn to item 1 to k of myPath & gSep
  372.   set the itemDelimiter to oldDelimiter
  373.   return myReturn
  374. end
  375.  
  376. on ExtractParentFolderName myPath
  377.   global gSep
  378.   set oldDelimiter to the itemDelimiter
  379.   set the itemDelimiter to gSep
  380.   set k to the number of items in myPath - 1
  381.   set myReturn to item k of myPath & gSep
  382.   set the itemDelimiter to oldDelimiter
  383.   return myReturn
  384. end
  385.  
  386. on SourceToDestFolder sourceFold
  387.   global gSourceFolder, gDestFolder
  388.   set s to the number of items in gSourceFolder - 1
  389.   set SemiDestFold to item 1 to the number of items in gDestFolder - 1 of gDestFolder
  390.   set destFold to sourceFold
  391.   put SemiDestFold into item 1 to s of destFold
  392.   return destFold
  393. end
  394.  
  395. on DestToSourceFolder destFold
  396.   global gSourceFolder, gDestFolder
  397.   set s to the number of items in gDestFolder - 1
  398.   set SemiSourceFold to item 1 to the number of items in gSourceFolder - 1 of gSourceFolder
  399.   set sourceFold to destFold
  400.   put SemiSourceFold into item 1 to s of sourceFold
  401.   return sourceFold
  402. end
  403.  
  404. on SaveLogFile
  405.   global gDirLog, gBigTextLog, gOneDirection, gMyLogFilePath, gLogPathList
  406.   if OSIsDirectory(gDirLog) = 0 then
  407.     set parID to ExtractParentFolder(gDirLog)
  408.     set fileName to ExtractFileNameFromPath(gDirLog)
  409.     set newPathName to gDirLog
  410.     set k to 0
  411.     repeat while OSIsDirectory(newPathName) = 0
  412.       set k to k + 1
  413.       set lun to 30 - length(string(k))
  414.       set newPathName to parID & Sinistra(fileName, lun) & "." & string(k)
  415.     end repeat
  416.     set NewName to ExtractFileNameFromPath(newPathName)
  417.     set err to OSRename(gDirLog, NewName)
  418.     if err then
  419.       AlertBox("Error renaming file" && QUOTE & newPathName & QUOTE & ".")
  420.       exit
  421.     end if
  422.   end if
  423.   if OSIsDirectory(gDirLog) = -43 then
  424.     set err to OSCreateDir(the pathName, "Log Files")
  425.     if err then
  426.       AlertBox("Error creating Folder" && QUOTE & "Log" & QUOTE & ".")
  427.       exit
  428.     end if
  429.   end if
  430.   if gOneDirection <> 1 then
  431.     set myPrefix to "Sync_"
  432.   else
  433.     set myPrefix to "Bckp_"
  434.   end if
  435.   set myFileName to myPrefix & GetDateAndTime()
  436.   set gMyLogFilePath to PuntoDuplicati(gDirLog & myFileName)
  437.   SaveTextFile(gMyLogFilePath, gBigTextLog, "TEXT")
  438.   append(gLogPathList, gMyLogFilePath)
  439. end
  440.  
  441. on PuntoDuplicati sourceFile
  442.   set parID to ExtractParentFolder(sourceFile)
  443.   set fileName to ExtractFileNameFromPath(sourceFile)
  444.   set newPathName to sourceFile
  445.   set k to 0
  446.   repeat while (OSIsDirectory(newPathName) = 0) or (OSIsDirectory(newPathName) = 1)
  447.     set k to k + 1
  448.     set lun to 30 - length(string(k))
  449.     set newPathName to parID & Sinistra(fileName, lun) & "." & string(k)
  450.   end repeat
  451.   return newPathName
  452. end
  453.  
  454. on ScriviFilePreference
  455.   global gDirPref, gNomeFilePref, gRememberFolders, gTopFolder, gBottomFolder, gRememberMultiList, gMultiAll, gMultiOnList, gMultiPathSourceList, gMultiPathDestList, gMaxMulti, gRememberTimer, gTimerAll, gTimerOnList, gTimerHourList, gTimerDayList, gMaxTimer, gTimerBy, gAppliedHourList, gAppliedDayList, gDaysInterval, gHoursInterval, gMinutesInterval, gStartMonth, gStartDay, gStartYear, gStartHour, gStartMinute, gStartInterval, gTheInterval
  456.   if not gRememberFolders then
  457.     set gTopFolder to EMPTY
  458.     set gBottomFolder to EMPTY
  459.   end if
  460.   if not gRememberMultiList then
  461.     set gMultiAll to 0
  462.     repeat with i = 1 to gMaxMulti
  463.       setAt(gMultiOnList, i, 1)
  464.       setAt(gMultiPathSourceList, i, 0)
  465.       setAt(gMultiPathDestList, i, 0)
  466.     end repeat
  467.   end if
  468.   if not gRememberTimer then
  469.     set gTimerAll to 0
  470.     set gTimerBy to 1
  471.     set gAppliedHourList to []
  472.     set gAppliedDayList to []
  473.     repeat with i = 1 to gMaxTimer
  474.       setAt(gTimerOnList, i, 1)
  475.       setAt(gTimerHourList, i, " ")
  476.       setAt(gTimerDayList, i, -1)
  477.     end repeat
  478.     set gDaysInterval to -1
  479.     set gHoursInterval to -1
  480.     set gMinutesInterval to -1
  481.     set gStartMonth to -1
  482.     set gStartDay to -1
  483.     set gStartYear to -1
  484.     set gStartHour to -1
  485.     set gStartMinute to -1
  486.     set gStartInterval to -1
  487.     set gTheInterval to -1
  488.   end if
  489.   set myPreferenze to getPreferenze()
  490.   if OSIsDirectory(gDirPref & gNomeFilePref) = 0 then
  491.     OSDelete(gDirPref & gNomeFilePref)
  492.   end if
  493.   SaveTextFile(gDirPref & gNomeFilePref, myPreferenze)
  494. end
  495.  
  496. on getPreferenze
  497.   global gTopFolder, gBottomFolder, gBeepWhenDone, gSaveLogFile, gRememberFolders, gOneDirection, gDestructive, gInvisible, gUnlockFile, gOnErrorDo, gAskConfirm, gFilterAll, gFilterCopySkip, gFilterOn, gFilterType, gFilterCreat, gFilterOper, gFilterDate, gLastBackUpDate, gMultiAll, gRememberMultiList, gMultiOnList, gMultiPathSourceList, gMultiPathDestList, gTimerAll, gRememberTimer, gTimerBy, gTimerOnList, gTimerHourList, gTimerDayList, gAppliedHourList, gAppliedDayList, gDoAndQuit, gDaysInterval, gHoursInterval, gMinutesInterval, gStartMonth, gStartDay, gStartYear, gStartHour, gStartMinute, gStartInterval, gTheInterval, gRectReport, gRectWindDate, gRectWindTimerHour
  498.   set mystringa to "--SETTAGGI PREFERENZE" & RETURN & "global gTopFolder, gBottomFolder" & RETURN & "global gBeepWhenDone, gSaveLogFile, gRememberFolders" & RETURN & "global gOneDirection, gDestructive, gInvisible" & RETURN & "global gUnlockFile, gOnErrorDo, gAskConfirm" & RETURN & RETURN & "global gFilterAll, gFilterCopySkip" & RETURN & "global gFilterOn, gFilterType, gFilterCreat, gFilterOper, gFilterDate, gLastBackUpDate" & RETURN & RETURN & "global gMultiAll, gRememberMultiList, gMultiOnList, gMultiPathSourceList, gMultiPathDestList" & RETURN & RETURN & "global gTimerAll, gRememberTimer, gTimerBy" & RETURN & RETURN & "global gTimerOnList, gTimerHourList, gTimerDayList" & RETURN & "global gAppliedHourList, gAppliedDayList, gDoAndQuit" & RETURN & RETURN & "global gDaysInterval, gHoursInterval, gMinutesInterval" & RETURN & "global gStartMonth, gStartDay, gStartYear, gStartHour, gStartMinute" & RETURN & "global gStartInterval, gTheInterval" & RETURN & RETURN & "global gRectReport, gRectWindDate, gRectWindTimerHour" & RETURN & RETURN & RETURN & "set gTopFolder=" & SostApici(gTopFolder) & RETURN & "set gBottomFolder=" & SostApici(gBottomFolder) & RETURN & "set gRememberFolders=" & gRememberFolders & RETURN & "set gOneDirection=" & gOneDirection & RETURN & "set gDestructive=" & gDestructive & RETURN & "set gBeepWhenDone=" & gBeepWhenDone & RETURN & "set gSaveLogFile=" & gSaveLogFile & RETURN & "set gInvisible=" & gInvisible & RETURN & "set gUnlockFile=" & gUnlockFile & RETURN & "set gOnErrorDo=" & gOnErrorDo & RETURN & "set gAskConfirm=" & gAskConfirm & RETURN & "set gFilterAll=" & gFilterAll & RETURN & "set gFilterCopySkip=" & gFilterCopySkip & RETURN & "set gFilterOn=" & gFilterOn & RETURN & "set gFilterType=value(" & SostApici(string(gFilterType)) & ")" & RETURN & "set gFilterCreat=value(" & SostApici(string(gFilterCreat)) & ")" & RETURN & "set gFilterOper=value(" & SostApici(string(gFilterOper)) & ")" & RETURN & "set gFilterDate=value(" & SostApici(string(gFilterDate)) & ")" & RETURN & "set gLastBackUpDate=value(" & SostApici(string(gLastBackUpDate)) & ")" & RETURN & "set gRectReport=" & gRectReport & RETURN & "set gRectWindDate=" & gRectWindDate & RETURN & "set gRectWindTimerHour=" & gRectWindTimerHour & RETURN & RETURN & "set gMultiAll=" & gMultiAll & RETURN & "set gRememberMultiList=" & gRememberMultiList & RETURN & "set gMultiOnList=" & gMultiOnList & RETURN & "set gMultiPathSourceList=value(" & SostApici(string(gMultiPathSourceList)) & ")" & RETURN & "set gMultiPathDestList=value(" & SostApici(string(gMultiPathDestList)) & ")" & RETURN & "ImpostagSourceDestFolders" & RETURN & RETURN & "set gTimerAll=" & gTimerAll & RETURN & "set gRememberTimer=" & gRememberTimer & RETURN & "set gTimerBy=" & gTimerBy & RETURN & RETURN & "set gTimerOnList=" & gTimerOnList & RETURN & "set gTimerHourList=value(" & SostApici(string(gTimerHourList)) & ")" & RETURN & "set gTimerDayList=" & gTimerDayList & RETURN & "set gAppliedHourList=value(" & SostApici(string(gAppliedHourList)) & ")" & RETURN & "set gAppliedDayList=" & gAppliedDayList & RETURN & "set gDoAndQuit=" & gDoAndQuit & RETURN & "PrepareTimerToDoList()" & RETURN & RETURN & "set gDaysInterval=" & gDaysInterval & RETURN & "set gHoursInterval=" & gHoursInterval & RETURN & "set gMinutesInterval=" & gMinutesInterval & RETURN & "set gStartMonth=" & gStartMonth & RETURN & "set gStartDay=" & gStartDay & RETURN & "set gStartYear=" & gStartYear & RETURN & "set gStartHour=" & gStartHour & RETURN & "set gStartMinute=" & gStartMinute & RETURN & "set gStartInterval=" & gStartInterval & RETURN & "set gTheInterval=" & gTheInterval & RETURN
  499.   return mystringa
  500. end
  501.  
  502. on SostApici Testo
  503.   set Lungh to length(Testo)
  504.   set retTesto to QUOTE
  505.   repeat with i = 1 to Lungh
  506.     set myChar to char i of Testo
  507.     if myChar = QUOTE then
  508.       put QUOTE & ""E&" & QUOTE after retTesto
  509.       next repeat
  510.     end if
  511.     put myChar after retTesto
  512.   end repeat
  513.   put QUOTE after retTesto
  514.   return retTesto
  515. end
  516.  
  517. on LeggiPreferenze
  518.   global gDirPref, gNomeFilePref
  519.   if OSIsDirectory(gDirPref & gNomeFilePref) = 0 then
  520.     set file to new(xtra("fileio"))
  521.     if objectp(file) then
  522.       openFile(file, gDirPref & gNomeFilePref, 0)
  523.       set myscript to readFile(file)
  524.       if PC() then
  525.         set myscript to RimuoviLineFeed(myscript)
  526.       end if
  527.       closeFile(file)
  528.       set file to 0
  529.       do(myscript)
  530.     end if
  531.   end if
  532. end
  533.  
  534. on AccorciaNome path, maxlun
  535.   global gSep
  536.   if voidp(maxlun) then
  537.     set maxlun to 49
  538.   end if
  539.   set lun to length(path)
  540.   if lun <= maxlun then
  541.     if the last char in path = gSep then
  542.       delete char -30000 of path
  543.     end if
  544.     return path
  545.     return Sinistra(path, lun)
  546.   end if
  547.   set maxLunP to 11
  548.   set maxLunF to maxlun - maxLunP
  549.   set myFolder to ExtractFileNameFromPath(path)
  550.   set myTempLunF to length(myFolder)
  551.   if myTempLunF > maxLunF then
  552.     set myFolder to Sinistra(myFolder, maxLunF - 3) & "..."
  553.   end if
  554.   set maxLunF to length(myFolder)
  555.   set maxLunP to maxlun - maxLunF
  556.   set myPar to ExtractParentFolder(path)
  557.   set myTempLunP to length(myPar)
  558.   if myTempLunP > maxLunP then
  559.     set myPar to Sinistra(myPar, maxLunP - 3) & "..."
  560.   end if
  561.   return myPar & myFolder
  562. end
  563.  
  564. on ConfrontaRecenteFile sourceF, destF
  565.   set a to OSFileModify(sourceF)
  566.   set b to OSFileModify(destF)
  567.   if a = b then
  568.     return 0
  569.   end if
  570.   if (a = EMPTY) or (b = EMPTY) or (a < 0) or (b < 0) then
  571.     return 1
  572.   end if
  573.   set oldDelimiter to the itemDelimiter
  574.   set the itemDelimiter to ","
  575.   set myDateA to item 1 of a
  576.   set myTimeA to item 2 of a
  577.   set myDateB to item 1 of b
  578.   set myTimeB to item 2 of b
  579.   set the itemDelimiter to "/"
  580.   set myYearA to value(item 1 of myDateA)
  581.   set myMonthA to value(item 2 of myDateA)
  582.   set myDayA to value(item 3 of myDateA)
  583.   set myYearB to value(item 1 of myDateB)
  584.   set myMonthB to value(item 2 of myDateB)
  585.   set myDayB to value(item 3 of myDateB)
  586.   set the itemDelimiter to oldDelimiter
  587.   if myYearA > myYearB then
  588.     return 1
  589.   end if
  590.   if myYearB > myYearA then
  591.     return 2
  592.   end if
  593.   if myMonthA > myMonthB then
  594.     return 1
  595.   end if
  596.   if myMonthB > myMonthA then
  597.     return 2
  598.   end if
  599.   if myDayA > myDayB then
  600.     return 1
  601.   end if
  602.   if myDayB > myDayA then
  603.     return 2
  604.   end if
  605.   set the itemDelimiter to ":"
  606.   set myHourA to value(item 1 of myTimeA)
  607.   set myMinuA to value(item 2 of myTimeA)
  608.   set mySecoA to value(item 3 of myTimeA)
  609.   set myHourB to value(item 1 of myTimeB)
  610.   set myMinuB to value(item 2 of myTimeB)
  611.   set mySecoB to value(item 3 of myTimeB)
  612.   set the itemDelimiter to oldDelimiter
  613.   if myHourA > myHourB then
  614.     return 1
  615.   end if
  616.   if myHourB > myHourA then
  617.     return 2
  618.   end if
  619.   if myMinuA > myMinuB then
  620.     return 1
  621.   end if
  622.   if myMinuB > myMinuA then
  623.     return 2
  624.   end if
  625.   if mySecoA > mySecoB then
  626.     return 1
  627.   end if
  628.   if mySecoB > mySecoA then
  629.     return 2
  630.   end if
  631. end
  632.  
  633. on CheckSyncButton
  634.   global gSourceFolder, gDestFolder, gNero, gGrigio, gSyncPermitted, gOneDirection
  635.   set gSyncPermitted to (gDestFolder <> EMPTY) and (gSourceFolder <> EMPTY)
  636.   if gSyncPermitted then
  637.     set the foreColor of member "P4" to gNero
  638.   else
  639.     set the foreColor of member "P4" to gGrigio
  640.   end if
  641.   set the enabled of menuItem 3 of menu "File" to gSyncPermitted
  642. end
  643.  
  644. on CheckOneDirection
  645.   global gOneDirection
  646.   if gOneDirection then
  647.     put "BackUp" into field "P4"
  648.     set the name of menuItem 3 of menu "File" to "BackUp"
  649.   else
  650.     put "Synchronize" into field "P4"
  651.     set the name of menuItem 3 of menu "File" to "Synchronize"
  652.   end if
  653.   set the picture of member "ICNBack" to the picture of member ("ICNBack" & string(gOneDirection))
  654.   updateStage()
  655. end
  656.  
  657. on NoSelectedFolders
  658.   global gSourceFolder, gDestFolder
  659.   set err to 0
  660.   if (gSourceFolder = EMPTY) or voidp(gSourceFolder) then
  661.     set err to 1
  662.   else
  663.     if (gDestFolder = EMPTY) or voidp(gDestFolder) then
  664.       set err to 3
  665.     end if
  666.   end if
  667.   if err = 0 then
  668.     return err
  669.   end if
  670.   case err of
  671.     1:
  672.       set ALRTmessaggio to "Choose the 1st Folder by clicking on the Top Folder Icon."
  673.     3:
  674.       set ALRTmessaggio to "Choose the 2nd Folder by clicking on the Bottom Folder Icon."
  675.   end case
  676.   AlertBox(ALRTmessaggio)
  677.   return err
  678. end
  679.  
  680. on NoValidFolders
  681.   global gSourceFolder, gDestFolder, gStopTimerAll, gOnErrorDo, gSaveLogFile, gBigTextLog, gShortTextLog
  682.   set err to 0
  683.   if OSIsDirectory(gSourceFolder) <> 1 then
  684.     set err to 2
  685.   else
  686.     if OSIsDirectory(gDestFolder) <> 1 then
  687.       set err to 4
  688.     end if
  689.   end if
  690.   if err = 0 then
  691.     return err
  692.   end if
  693.   case err of
  694.     2:
  695.       set ALRTmessaggio to "Cannot found the 1st Folder" && QUOTE & AccorciaNome(gSourceFolder) & QUOTE & "."
  696.       set LOGmessaggio to ALRTmessaggio & RETURN & myOperation() & " stopped."
  697.     4:
  698.       set ALRTmessaggio to "Cannot found the 2nd Folder" && QUOTE & AccorciaNome(gDestFolder) & QUOTE & "."
  699.       set LOGmessaggio to ALRTmessaggio & RETURN & myOperation() & " stopped."
  700.   end case
  701.   if gOnErrorDo = 0 then
  702.     AlertBox(ALRTmessaggio & MsgTimer())
  703.   end if
  704.   put LOGmessaggio after gBigTextLog
  705.   if gSaveLogFile then
  706.     SaveLogFile()
  707.   end if
  708.   set gBigTextLog to EMPTY
  709.   return err
  710. end
  711.  
  712. on GetDateAndTime
  713.   set myDT to OSConstDate()
  714.   set Lungh to length(myDT)
  715.   repeat with i = 1 to Lungh
  716.     if (char i of myDT = "/") or (char i of myDT = ",") or (char i of myDT = ":") then
  717.       put "_" into char i of myDT
  718.     end if
  719.   end repeat
  720.   return myDT
  721. end
  722.  
  723. on GetModifDate sourceF
  724.   set a to OSFileModify(sourceF)
  725.   set oldDelimiter to the itemDelimiter
  726.   set the itemDelimiter to ","
  727.   set myDateA to item 1 of a
  728.   set the itemDelimiter to "/"
  729.   set myYearA to value(item 1 of myDateA)
  730.   set myMonthA to MeseCorto(value(item 2 of myDateA))
  731.   set myDayA to value(item 3 of myDateA)
  732.   set the itemDelimiter to oldDelimiter
  733.   return string(myDayA) && myMonthA && string(myYearA)
  734. end
  735.  
  736. on TodayYear stringa
  737.   set x to Sinistra(OSConstDate(), 4)
  738.   if stringa then
  739.     return x
  740.   end if
  741.   return value(x)
  742. end
  743.  
  744. on TodayMonth stringa
  745.   set x to Centro(OSConstDate(), 6, 7)
  746.   if stringa then
  747.     return x
  748.   end if
  749.   return value(x)
  750. end
  751.  
  752. on TodayDay stringa
  753.   set x to Centro(OSConstDate(), 9, 10)
  754.   if stringa then
  755.     return x
  756.   end if
  757.   return value(x)
  758. end
  759.  
  760. on NowHour stringa
  761.   set x to Centro(OSConstDate(), 12, 13)
  762.   if stringa then
  763.     return x
  764.   end if
  765.   return value(x)
  766. end
  767.  
  768. on NowMinute stringa
  769.   set x to Centro(OSConstDate(), 15, 16)
  770.   if stringa then
  771.     return x
  772.   end if
  773.   return value(x)
  774. end
  775.  
  776. on MeseCorto numMese
  777.   case numMese of
  778.     1:
  779.       return "jen"
  780.     2:
  781.       return "feb"
  782.     3:
  783.       return "mar"
  784.     4:
  785.       return "apr"
  786.     5:
  787.       return "may"
  788.     6:
  789.       return "jun"
  790.     7:
  791.       return "jul"
  792.     8:
  793.       return "aug"
  794.     9:
  795.       return "gSep"
  796.     10:
  797.       return "oct"
  798.     11:
  799.       return "nov"
  800.     12:
  801.       return "dec"
  802.   end case
  803.   return "   "
  804. end
  805.  
  806. on MeseNum mese
  807.   case mese of
  808.     "jen":
  809.       return "01"
  810.     "feb":
  811.       return "02"
  812.     "mar":
  813.       return "03"
  814.     "apr":
  815.       return "04"
  816.     "may":
  817.       return "05"
  818.     "jun":
  819.       return "06"
  820.     "jul":
  821.       return "07"
  822.     "aug":
  823.       return "08"
  824.     "gSep":
  825.       return "09"
  826.     "oct":
  827.       return 10
  828.     "nov":
  829.       return 11
  830.     "dec":
  831.       return 12
  832.   end case
  833.   return "00"
  834. end
  835.  
  836. on SecondsInMinute myTime
  837.   set ore to myTime / 3600
  838.   set minuti to myTime / 60 mod 60
  839.   set secondi to myTime mod 60
  840.   if ore < 10 then
  841.     set ore to "0" & ore & ":"
  842.   end if
  843.   if minuti < 10 then
  844.     set minuti to "0" & minuti
  845.   end if
  846.   if secondi < 10 then
  847.     set secondi to "0" & secondi
  848.   end if
  849.   return ore & minuti & ":" & secondi
  850. end
  851.  
  852. on GetUniquePathNameInFolder destFold
  853.   global gSep
  854.   set parID to ExtractParentFolder(destFold)
  855.   set fileName to ExtractFileNameFromPath(destFold)
  856.   set newPathName to parID & fileName
  857.   set k to 0
  858.   repeat while (OSIsDirectory(newPathName) >= 0) or (OSIsDirectory(DestToSourceFolder(newPathName)) >= 0)
  859.     set k to k + 1
  860.     set lun to 30 - length(string(k))
  861.     set newPathName to parID & Sinistra(fileName, lun) & "." & string(k)
  862.   end repeat
  863.   return newPathName
  864. end
  865.  
  866. on SetHeaderLogFile
  867.   global gMultiAll, gMultiXSource, gIterMulti, gOneDirection, gFilterAll, gFilterTextLog, gNumFilters, gSourceFolder, gDestFolder, gBigTextLog, gShortTextLog, gBeepWhenDone, gSaveLogFile, gRememberFolders, gInvisible, gUnlockFile, gDestructive, gOnErrorDo, gAskConfirm
  868.   set gBigTextLog to EMPTY
  869.   if gMultiAll then
  870.     set TotMulti to count(gMultiXSource)
  871.     set StringaMulti to "Multiple (" & string(gIterMulti) & " of " & TotMulti & ") "
  872.   else
  873.     set StringaMulti to EMPTY
  874.   end if
  875.   if gOneDirection then
  876.     set myOperation to "BackUp"
  877.   else
  878.     set myOperation to "Synchronization"
  879.   end if
  880.   set myStrFiltri to EMPTY
  881.   if gFilterAll and (gNumFilters > 0) then
  882.     set StringaFiltri to "(with" && gNumFilters && "filters) "
  883.   else
  884.     set StringaFiltri to EMPTY
  885.   end if
  886.   set gBigTextLog to StringaMulti & myOperation && StringaFiltri & "from:" & RETURN & gSourceFolder && "to:" & RETURN & gDestFolder & RETURN & RETURN
  887.   put "Preferences: " & RETURN & "If an error occurred:" && StopSkip(gOnErrorDo) & RETURN & "Beep When Done:" && YesNot(gBeepWhenDone) & RETURN & "Save Log File:" && YesNot(gSaveLogFile) & RETURN & "Remember Folders:" && YesNot(gRememberFolders) & RETURN & "One Direction Only:" && YesNot(gOneDirection) & RETURN & "Exact BackUp:" && YesNot(gDestructive) & RETURN & "Invisible Items:" && YesNot(gInvisible) & RETURN & "Unlock locked files:" && YesNot(gUnlockFile) & RETURN & "Ask Confirm:" && YesNot(gAskConfirm) & RETURN & "--" & RETURN after gBigTextLog
  888.   if gFilterAll and (gNumFilters > 0) then
  889.     put gFilterTextLog after gBigTextLog
  890.   end if
  891.   put "Start at:" && the long date && "-" && the long time & RETURN after gBigTextLog
  892.   set gShortTextLog to gBigTextLog
  893. end
  894.  
  895. on YesNot Valore
  896.   if Valore then
  897.     return "Yes"
  898.   else
  899.     return "No"
  900.   end if
  901. end
  902.  
  903. on StopSkip Valore
  904.   if Valore then
  905.     return "Skip"
  906.   else
  907.     return "Stop"
  908.   end if
  909. end
  910.  
  911. on myOperation
  912.   global gOneDirection, gIterMulti
  913.   if gOneDirection then
  914.     if (gIterMulti - 1) > 1 then
  915.       return "BackUps"
  916.     else
  917.       return "BackUp"
  918.     end if
  919.   else
  920.     if (gIterMulti - 1) > 1 then
  921.       return "Synchronizations"
  922.     else
  923.       return "Synchronization"
  924.     end if
  925.   end if
  926. end
  927.  
  928. on MyOperationBtn
  929.   global gOneDirection
  930.   if gOneDirection then
  931.     return "BackUp"
  932.   else
  933.     return "Synchronize"
  934.   end if
  935. end
  936.